package org.prism.Lc;

import java.util.HashMap;

public class LetCode {
    public static void main(String[] args) {
//        int number = findMaxNumber(new int[]{1, 2, 5, 9, 5, 9, 5, 5, 5});
//        System.out.println("number = " + number);
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1,"张三");
    }

    public static int findMaxNumber(int[] arr){
        int candidate = -1;
        int count = 0;
        for (int num : arr) {
            if(count == 0){
                candidate = num;
            }
            if(num == candidate){
                count++;
            }else {
                count--;
            }
        }
        count = 0;
        int length = arr.length;
        for (int num : arr) {
            if(num == candidate){
                count++;
            }
        }
        return count * 2 > length ? candidate : -1;
    }
}
